package com.pkk.cloud.support.admin.oauth2.api.common.resp;

import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * @description:自定义的用户信息
 * @author: peikunkun
 * @create: 2020-03-18 14:31
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Oauth2UserDetails implements UserDetails, CredentialsContainer {

  private static final long serialVersionUID = 537914385173185111L;

  /**
   * 自定义的用户信息
   */
  private UserInfo userInfo;

  private User user;

  @Override
  public void eraseCredentials() {
    user.eraseCredentials();
  }

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    return user.getAuthorities();
  }

  @Override
  public String getPassword() {
    return user.getPassword();
  }

  @Override
  public String getUsername() {
    return user.getUsername();
  }

  @Override
  public boolean isAccountNonExpired() {
    return user.isAccountNonExpired();
  }

  @Override
  public boolean isAccountNonLocked() {
    return user.isAccountNonLocked();
  }

  @Override
  public boolean isCredentialsNonExpired() {
    return user.isCredentialsNonExpired();
  }

  @Override
  public boolean isEnabled() {
    return user.isEnabled();
  }
}